package com.example.dormmanage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dormmanage.entity.Menu;
import com.example.dormmanage.service.impl.MenuService;
import com.example.dormmanage.view.MenuDto;
import com.example.dormmanage.view.ResultView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
@Api(tags = "菜单管理")
@Slf4j
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping()
    @ApiOperation("查询菜单列表")
    public ResultView<List<MenuDto>> selectMenuList(){
        return menuService.selectMenuList();
    }

    @PostMapping("/addFather")
    @ApiOperation("添加父级菜单")
    public ResultView<String> addFatherMenu(@RequestBody Menu menu){
        return menuService.addFatherMenu(menu);
    }

    @PostMapping("/addSon")
    @ApiOperation("添加子级菜单")
    public ResultView<String> addSonMenu(@RequestBody Menu menu){
        return menuService.addSonMenu(menu);
    }

    @DeleteMapping("/{menuId}")
    @ApiOperation("删除菜单")
    public ResultView<String> deleteMenu(@PathVariable Integer menuId){
        return menuService.deleteMenu(menuId);
    }

    @GetMapping("/{menuId}")
    @ApiOperation("查询菜单详情")
    public ResultView<Menu> selectMenuDetail(@PathVariable Integer menuId){
        return menuService.selectMenuDetail(menuId);
    }


    @PutMapping
    @ApiOperation("修改菜单")
    public ResultView<String> updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }
}
